﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.So;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model.Wms;

namespace nERP.ViewModel.So.SaleReturnDetailVMs
{
    public partial class SaleReturnDetailListVM : BasePagedListVM<SaleReturnDetail_View, SaleReturnDetailSearcher>
    {

        protected override IEnumerable<IGridColumn<SaleReturnDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<SaleReturnDetail_View>>{

                this.MakeGridHeader(x => x.SaleReturnDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_SaleReturn).SetTitle(@Localizer["Page.销售退货"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_SaleReturnDetailCode).SetTitle(@Localizer["Page.退货明细单号"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_SaleOutWarehouseDetail).SetTitle(@Localizer["Page.销售出库明细"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_Sale).SetTitle(@Localizer["Page.销售订单"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_SaleDetail).SetTitle(@Localizer["Page.销售明细"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_Goods).SetTitle(@Localizer["Page.商品"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_GoodsName).SetTitle(@Localizer["Page.商品名称"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_GoodsSpec).SetTitle(@Localizer["Page.商品规格"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_GoodsUnit).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_ReturnNumber).SetTitle(@Localizer["Page.退货数量"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_UnitPrice).SetTitle(@Localizer["Page.退货单价"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_DiscountPrice).SetTitle(@Localizer["Page.折扣金额"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_TotalPrice).SetTitle(@Localizer["Page.退货金额"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_TaxRate).SetTitle(@Localizer["Page.税率"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_TaxUnitPrice).SetTitle(@Localizer["Page.含税单价"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_TaxPrice).SetTitle(@Localizer["Page.税额"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_TotalTaxPrice).SetTitle(@Localizer["Page.含税金额"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.SaleReturnDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }


        public override IOrderedQueryable<SaleReturnDetail_View> GetSearchQuery()
        {
            var query = DC.Set<SaleReturnDetail>()

                .CheckEqual(Searcher.Seq, x => x.Seq)
                .CheckEqual(Searcher.SaleReturnId, x => x.SaleReturnId)
                .CheckContain(Searcher.SaleReturnDetailCode, x => x.SaleReturnDetailCode)
                .CheckEqual(Searcher.SaleOutWarehouseDetailId, x => x.SaleOutWarehouseDetailId)
                .CheckEqual(Searcher.SaleId, x => x.SaleId)
                .CheckEqual(Searcher.SaleDetailId, x => x.SaleDetailId)
                .CheckEqual(Searcher.GoodsId, x => x.GoodsId)
                .CheckContain(Searcher.GoodsName, x => x.GoodsName)
                .CheckContain(Searcher.GoodsSpec, x => x.GoodsSpec)
                .CheckContain(Searcher.GoodsUnit, x => x.GoodsUnit)
                .CheckEqual(Searcher.ReturnNumber, x => x.ReturnNumber)
                .CheckEqual(Searcher.UnitPrice, x => x.UnitPrice)
                .CheckEqual(Searcher.DiscountPrice, x => x.DiscountPrice)
                .CheckEqual(Searcher.TotalPrice, x => x.TotalPrice)
                .CheckEqual(Searcher.TaxRate, x => x.TaxRate)
                .CheckEqual(Searcher.TaxUnitPrice, x => x.TaxUnitPrice)
                .CheckEqual(Searcher.TaxPrice, x => x.TaxPrice)
                .CheckEqual(Searcher.TotalTaxPrice, x => x.TotalTaxPrice)
                .CheckContain(Searcher.Remark, x => x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new SaleReturnDetail_View
                {
                    ID = x.ID,

                    SaleReturnDetail_Seq = x.Seq,
                    SaleReturnDetail_SaleReturn = DC.Set<SaleReturn>().Where(z0 => z0.SaleReturnCode == x.SaleReturnId).Select(y => y.SaleReturnCode).FirstOrDefault(),
                    SaleReturnDetail_SaleReturnDetailCode = x.SaleReturnDetailCode,
                    SaleReturnDetail_SaleOutWarehouseDetail = DC.Set<SaleOutWarehouseDetail>().Where(z0 => z0.SaleOutWarehouseDetailCode == x.SaleOutWarehouseDetailId).Select(y => y.SaleOutWarehouseDetailCode).FirstOrDefault(),
                    SaleReturnDetail_Sale = DC.Set<Sale>().Where(z0 => z0.SaleCode == x.SaleId).Select(y => y.SaleCode).FirstOrDefault(),
                    SaleReturnDetail_SaleDetail = DC.Set<SaleDetail>().Where(z0 => z0.SaleDetailCode == x.SaleDetailId).Select(y => y.SaleDetailCode).FirstOrDefault(),
                    SaleReturnDetail_Goods = x.GoodsId,// DC.Set<Goods>().Where(z0 => z0.GoodsCode == x.GoodsId).Select(y => y.GoodsName).FirstOrDefault(),
                    SaleReturnDetail_GoodsName = x.GoodsName,
                    SaleReturnDetail_GoodsSpec = x.GoodsSpec,
                    SaleReturnDetail_GoodsUnit = x.GoodsUnit,
                    SaleReturnDetail_ReturnNumber = x.ReturnNumber,
                    SaleReturnDetail_UnitPrice = x.UnitPrice,
                    SaleReturnDetail_DiscountPrice = x.DiscountPrice,
                    SaleReturnDetail_TotalPrice = x.TotalPrice,
                    SaleReturnDetail_TaxRate = x.TaxRate,
                    SaleReturnDetail_TaxUnitPrice = x.TaxUnitPrice,
                    SaleReturnDetail_TaxPrice = x.TaxPrice,
                    SaleReturnDetail_TotalTaxPrice = x.TotalTaxPrice,
                    SaleReturnDetail_Remark = x.Remark,
                    SaleReturnDetail_Status = x.Status,
                    SaleReturnDetail_CreateTime = x.CreateTime,
                    SaleReturnDetail_UpdateTime = x.UpdateTime,
                    SaleReturnDetail_CreateBy = x.CreateBy,
                    SaleReturnDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class SaleReturnDetail_View : SaleReturnDetail
    {

        public int? SaleReturnDetail_Seq { get; set; }
        public string SaleReturnDetail_SaleReturn { get; set; }
        public string SaleReturnDetail_SaleReturnDetailCode { get; set; }
        public string SaleReturnDetail_SaleOutWarehouseDetail { get; set; }
        public string SaleReturnDetail_Sale { get; set; }
        public string SaleReturnDetail_SaleDetail { get; set; }
        public string SaleReturnDetail_Goods { get; set; }
        public string SaleReturnDetail_GoodsName { get; set; }
        public string SaleReturnDetail_GoodsSpec { get; set; }
        public string SaleReturnDetail_GoodsUnit { get; set; }
        public decimal? SaleReturnDetail_ReturnNumber { get; set; }
        public decimal? SaleReturnDetail_UnitPrice { get; set; }
        public decimal? SaleReturnDetail_DiscountPrice { get; set; }
        public decimal? SaleReturnDetail_TotalPrice { get; set; }
        public decimal? SaleReturnDetail_TaxRate { get; set; }
        public decimal? SaleReturnDetail_TaxUnitPrice { get; set; }
        public decimal? SaleReturnDetail_TaxPrice { get; set; }
        public decimal? SaleReturnDetail_TotalTaxPrice { get; set; }
        public string SaleReturnDetail_Remark { get; set; }
        public dStatusTypeEnum? SaleReturnDetail_Status { get; set; }
        public DateTime? SaleReturnDetail_CreateTime { get; set; }
        public DateTime? SaleReturnDetail_UpdateTime { get; set; }
        public string SaleReturnDetail_CreateBy { get; set; }
        public string SaleReturnDetail_UpdateBy { get; set; }

    }

}